// 测量=======================================================================start
// 取消量算
cancelMeasure() {
	this.result.title = "";
	this.result.content = "";
	this.result.position = undefined;
},
/**
 * 开启测量
 */
toolOpenMeasure(type) {
	// 移除上一次交互
	if (this.draw) this.map.removeInteraction(this.draw);
	// 重置全局变量
	this.closeAllSwitchControl();
	// 开启测量
	this.measureSwitchControl = true;
	// 日志输出
	this.fnOutShowResultLogs({ title: "测量", content: `开启测量` });
	// 设置测量类型
	this.hasMeasureType = type;
	// startMeasure
	this.startMeasure(type);
},
/**
 * 关闭测量
 */
toolCloseMeasure() {
	// 设置测量类型
	this.hasMeasureType = null;
	// 移除上一次交互
	if (this.draw) this.map.removeInteraction(this.draw);
	// 重置全局变量
	this.closeAllSwitchControl();
	// 移除 测量tooltip 显示dom
	if (this.measureTooltipElementArr.length) {
		this.measureTooltipElementArr.forEach(itemEle => {
			if (itemEle) itemEle.parentNode.removeChild(itemEle);
		});
		this.measureTooltipElementArr = [];
	}
	// 移除 测量下一次 显示dom
	if (this.measureTooltipElement) {
		this.measureTooltipElement.parentNode.removeChild(this.measureTooltipElement);
		this.measureTooltipElement = null;
	}
	// 测量帮助提示 显示dom
	if (this.helpTooltipElement) {
		this.helpTooltipElement.parentNode.removeChild(this.helpTooltipElement);
		this.helpTooltipElement = null;
	}
	// 清空测量数据
	this.globalFeatures = [];
	// 日志输出
	this.fnOutShowResultLogs({ title: "测量", content: `关闭测量` });
},
/**
 * 开始量算
 */
startMeasure(type) {
	// tools 确定那个工具在使用中
	this.draw = new Draw({
		source: this.source,
		type: type == "area" ? "Polygon" : "LineString",
		// style: startStyle || undefined,
		style: new Style({
			fill: new FillStyle({
				color: "rgba(255, 255, 255, 0.2)",
			}),
			stroke: new StrokeStyle({
				color: "rgba(0, 0, 0, 0.5)",
				lineDash: [10, 10],
				width: 2,
			}),
			image: new CircleStyle({
				radius: 5,
				stroke: new StrokeStyle({
					color: "rgba(0, 0, 0, 0.7)",
				}),
				fill: new FillStyle({
					color: "rgba(255, 255, 255, 0.2)",
				}),
			}),
		}),
	});
	// 创建测量数值提示
	this.createMeasureTooltip();
	// 创建帮助提示
	this.createHelpTooltip();
	// 添加鼠标移出Map 窗口事件
	this.map.getViewport().addEventListener("mouseout", function () {
		if (this.helpTooltipElement) this.helpTooltipElement.classList.add("hidden");
	});
	// 绘制监听
	// 开始绘制
	this.draw.on("drawstart", this.handleDrawStart);
	// 结束绘制
	this.draw.on("drawend", this.handleDrawEnd);
	// 添加交互
	this.map.addInteraction(this.draw);
},
// 结束量算
handleDrawEnd() {
	// 测量 高亮提升
	this.measureTooltipElement.className = "ol-tooltip ol-tooltip-static";
	this.measureTooltip.setOffset([0, -7]);
	// 保存测量结果dom 节点 便于 删除
	this.measureTooltipElementArr = [...this.measureTooltipElementArr, this.measureTooltipElement];
	// 测量 Feature 缓存
	this.globalFeatures = [...this.globalFeatures, this.sketch];
	// 重置绘制 feature
	this.sketch = null;
	// unset tooltip so that a new one can be created
	this.measureTooltipElement = null;
	this.createMeasureTooltip();
	this.map.removeInteraction(this.draw);
	unByKey(this.listener);
	// 日志输出
	this.fnOutShowResultLogs({ title: "本次测量", content: `结束本次测量` });
	// this.endMeasure();
},
handleDrawStart(evt) {
	let feature = evt.feature;
	let tooltipCoord = evt.coordinate;
	this.sketch = feature;
	// 日志输出
	this.fnOutShowResultLogs({ title: "本次测量", content: `开始本次绘制` });
	// 监控绘制变化
	this.listener = feature.getGeometry().on("change", evt => {
		const geom = evt.target;
		let output;
		if (geom instanceof Polygon) {
			output = formatArea(geom);
			tooltipCoord = geom.getInteriorPoint().getCoordinates();
		} else if (geom instanceof LineString) {
			output = formatLength(geom);
			tooltipCoord = geom.getLastCoordinate();
		}
		this.measureTooltipElement.innerHTML = output;
		this.measureTooltip.setPosition(tooltipCoord);
		// 绘制结果
		this.result = this.result || {};
		this.result.content = output;
		this.result.position = tooltipCoord;
	});
},